package com.linq.cool.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linq.cool.common.constants.Constants;
import com.linq.cool.common.constants.UserConstants;
import com.linq.cool.system.domain.SysBanner;
import com.linq.cool.system.dto.SysBannerQueryDTO;
import com.linq.cool.system.mapper.SysBannerMapper;
import com.linq.cool.system.service.SysBannerService;
import org.springframework.stereotype.Service;

/**
 * @Author: yqlin
 * @Date: 2021/1/30 19:17
 * @Description:
 * @Version: 1.0.0
 */

@Service
public class SysBannerServiceImpl extends ServiceImpl<SysBannerMapper, SysBanner> implements SysBannerService {

    @Override
    public IPage<SysBanner> listByPage(IPage<SysBanner> page, SysBannerQueryDTO dto) {
        return this.page(page, this.getLambdaQueryWrapper(dto));
    }

    private LambdaQueryWrapper<SysBanner> getLambdaQueryWrapper(SysBannerQueryDTO dto) {
        return new LambdaQueryWrapper<SysBanner>()
                .eq(SysBanner::getIsDeleted, UserConstants.StateEnum.STATUS_NORMAL.getCode())
                .eq(StringUtils.checkValNotNull(dto.getStatus()), SysBanner::getStatus, dto.getStatus())
                .like(StringUtils.checkValNotNull(dto.getName()), SysBanner::getName, dto.getName())
                .between(StringUtils.checkValNotNull(dto.getParams().get(Constants.BEGIN_TIME)), SysBanner::getGmtCreate, dto.getParams().get(Constants.BEGIN_TIME), dto.getParams().get(Constants.END_TIME))
                ;
    }
}
